<style scoped>
</style>
<template>
  <RequestListCategorySlot :category_list="category_list" category_field="category_id" :category_id="category_id" :url="url" pull_refresh >
    <template #default="{row}">
      <Card v-bind="row" :href="info_href(row)" ></Card>
    </template>
  </RequestListCategorySlot>
</template>

<script>
import {ajax} from "@/js/api_tool.js";
import {_get} from "@/vue_plugin/router_auto.js";
import Card from "@/components/card/Card.vue";
import RequestListCategorySlot from "@/components/slot/RequestListCategorySlot.vue";

export default {
  components:{RequestListCategorySlot, Card},
  props: {
    model: Object,
    this_action: Object,
    is_admin: Boolean,
  },
  data(){
    return {
      url: `/home/${this.model.name}/${this.this_action.action}`,
      category_list: [],
      category_id: _get('category_id', ''),
    }
  },
  methods:{
    async get_category_list(){
      let url = `/home/category/list?where[model_name][eq]=${this.model.name}`;
      let res = await ajax(url);
      this.category_list = res.data?.list || [];
    },
    info_href(row){
      let info_action = this.model.canActionListHome(row).find(row=>row.type==='info');
      if (!info_action) return '';
      return `/model_base/info?model_name=${this.model.name}&action=${info_action.action}&id=${row.id}`
    },
  },
  computed:{
  },
  mounted(){
    this.get_category_list();
  }
}
</script>